<template>
  <div v-if="sureAdmin">
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item v-if="fromUrl == 1" :to="{ path: '/users' }"
        >用户管理
      </el-breadcrumb-item>
      <el-breadcrumb-item v-if="fromUrl == 2" :to="{ path: '/order' }"
        >订单管理</el-breadcrumb-item
      >
      <el-breadcrumb-item
        v-if="fromUrl == 2"
        :to="{ path: '/order/orderUser/' + this.$route.params.id }"
        >用户详情</el-breadcrumb-item
      >
      <el-breadcrumb-item>用户消费记录</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 用户列表区域 -->
      <el-table :data="userConsumeList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column
          label="消费单号"
          prop="number"
          sortable
          min-width="10%"
        ></el-table-column>
        <el-table-column
          label="用户名称"
          prop="userName"
          min-width="10%"
        ></el-table-column>
        <el-table-column
          label="消费金额"
          prop="usageRecord"
          sortable
          min-width="10%"
        ></el-table-column>
        <el-table-column
          label="消费时间"
          prop="time"
          sortable
          min-width="10%"
        ></el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 获取用户列表的参数对象
      queryInfo: {
        // 当前的页数
        pageNo: 1,
        // 当前每页显示多少条数据
        pageSize: 10,
        userId: 0,
      },
      userConsumeList: [],
      total: 0,
      sureAdmin: false,
      fromUrl: "",
    };
  },
  created() {
    var Admin = window.localStorage.getItem("admin");
    if (Admin == 1) {
      console.log(this.$route.params.id);
      this.queryInfo.userId = this.$route.params.id;
      this.fromUrl = this.$route.params.fromUrl;
      this.getConsume();
      this.sureAdmin = true;
      // this.getUserList();
    } else {
      this.sureAdmin = false;
    }
  },
  methods: {
    async getConsume() {
      const { data: res } = await this.$http.get("wallet/getConsume", {
        params: this.queryInfo,
      });
      // console.log(res,"sssssssssssssssssssssssssssssssssssssss");
      if (res.code !== 200) {
        return this.$message.error("获取消费列表失败！");
      }
      this.userConsumeList = res.data.listDetailedVOs;
      this.total = res.data.count;
    },

    // 监听 pagesize 改变的事件
    handleSizeChange(newSize) {
      // console.log(newSize)
      this.queryInfo.pageSize = newSize;
      this.getConsume();
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(newPage) {
      console.log(newPage);
      this.queryInfo.pageNo = newPage;
      this.getConsume();
    },
  },
};
</script>

<style lang="less" scoped>
.button:hover {
  background-color: rgb(64, 158, 255);
  color: rgb(255, 255, 255);
}
</style>
